import tailwindcss from '@tailwindcss/vite'
import { VantResolver } from '@vant/auto-import-resolver'
import vue from '@vitejs/plugin-vue'
import autoprefixer from 'autoprefixer'

import mobile from 'postcss-mobile-forever' // <---- 这里

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import VueRouter from 'unplugin-vue-router/vite'

import { defineConfig } from 'vite'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    tailwindcss(),
    VueRouter(),
    vue(),
    AutoImport({
      resolvers: [VantResolver()],
    }),
    Components({
      resolvers: [VantResolver()],
    }),
  ],
  css: {
    postcss: {
      plugins: [
        autoprefixer(),
        mobile({
          appSelector: '#app',
          viewportWidth: file => file.includes('vant') ? 375 : 750,
          maxDisplayWidth: 580,
        }),
      ],
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'https://app.gracelore.cc',
        changeOrigin: true,
      },
    },
  },
})
